package com.woniuxy.ticketauth.controller;

import com.woniuxy.commnes.entity.ResponseResult;
import com.woniuxy.ticketauth.entity.Perm;
import com.woniuxy.ticketauth.jwt.Audience;
import com.woniuxy.ticketauth.jwt.JwtUtil;
import com.woniuxy.ticketauth.service.PermService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName MenuCountroller
 * @Description TODO
 * @Author zx
 * @Date 2021-03-03 19:17:44
 * @Version 1.0
 */
@RestController
@RequestMapping("menu")
public class MenuController {
    @Resource
    private PermService permService;
    @Resource
    private Audience audience;

    @GetMapping("get")
    public ResponseResult<List<Perm>> getMenus(@RequestHeader("jwt") String jwt) {
        int id = JwtUtil.getUserId(jwt, audience.getBase64Secret());
        return new ResponseResult<List<Perm>>(permService.getMenuById(id));
    }
}
